<template>
  <div class="apparatus">
    <div class="title"> <span>器械要求</span></div>
    <div class="content">
      <button class="type-select" @click="searchbtn(apparatus_init);clickfun($event)">{{apparatus_init}}</button>
      <button @click="searchbtn(apparatus.name);clickfun($event)" v-for="apparatus in apparatus_list">{{apparatus.name}}</button>
    </div>
  </div>
</template>

<script>
    export default{
        name: "Apparatus",
      data(){
          return{
              apparatus_init:"不限器械",
              apparatus_list:[],
              apparatus_type:"不限器械",

          }
      },
      created() {
        var this_=this
        this.$axios.get('http://127.0.0.1:8080/traning/qixie')
          .then(function (response) {
            this_.apparatus_list=response.data
          })
      },
      methods:{
          clickfun(e) {
          console.log(e.target)
          var nodes=e.target.parentNode.children
          for(var o of nodes){
            o.className='';
          }
          e.target.className='type-select'
        },
        searchbtn:function (btn){
          this.apparatus_type=btn
          if(this.apparatus_type==="不限器械"){
            this.$store.state.apparatus_type=''
            this.get_plan()
          }else{
            this.$store.state.apparatus_type=this.apparatus_type
            this.get_plan()
          }
        },
        get_plan:function () {
        let this_=this

            this_.$axios.get('http://127.0.0.1:8080/traning/jihua',{params: {
                search: this_.$store.state.search,
                day: this_.$store.state.day_type,
                qixie: this_.$store.state.apparatus_type,
                body_part: this_.$store.state.body_type,
                grade: this_.$store.state.grade_type,
                aim: this_.$store.state.aim_type,
              }})
          .then(function (response) {
            this_.$store.state.plan=response.data

          })

      }
    }
  }
</script>

<style scoped>
  .title{
    margin-bottom: 10px;
    margin-top: 20px;
    opacity: 0.8;
  }
  .type-select{
    opacity: 1;
    color: white;
    transform: scale(1.1);
  }
  button{
    outline: none;
    padding: 0;
    margin-left: 8px;
    margin-right: 5px;
    margin-bottom: 5px;
    padding-bottom: 2px;
    height: 20px;
    width: 52px;
    font-size: 12px;
    opacity: 0.7;
    border: 1px solid white;
    background: none;
    color: white;
    cursor:pointer
  }
  button:hover{
    opacity: 1;
  }
  .apparatus{
    width: 280px;
    margin-bottom: 30px;
  }
  .content{
    display: flex;
    flex-wrap: wrap;
  }
</style>
